package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {

	//生成client 参数为默认
	client := &http.Client{}

	//生成要访问的url
	url := "http://172.16.0.106/operation-manager/v2/api-docs"

	//提交请求
	reqest, err := http.NewRequest("GET", url, nil)

	if err != nil {
		panic(err)
	}

	//处理返回结果
	response, _ := client.Do(reqest)
	defer response.Body.Close()
	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		fmt.Errorf("调用失败")
	}
	context := string(body)
	//fmt.Printf("%v", context)
	contextMap := make(map[string]map[string]map[string]map[string]string)
	//字符串转json
	err = json.Unmarshal([]byte(context), &contextMap)
	if err != nil {
		fmt.Errorf("解析失败")
	}

	pathMap := contextMap["paths"]

	newPathMap := make(map[string]string)
	for k, v := range pathMap {
		m := v
		for _, vv := range m {
			newPathMap[k] = vv["summary"]
		}
	}

	mjson, _ := json.Marshal(contextMap["paths"])
	mString := string(mjson)
	fmt.Printf("print mString:%s", mString)

}
